package com.example.controller;
import com.example.common.Result;
import com.example.entity.*;
import com.example.entity.Class;
import com.example.entity.others.Test_User_Other;
import com.example.entity.others.User_Subject;
import com.example.service.SparkService;
import com.example.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService userService;
    @Resource
    SparkService sparkService;

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        user=userService.login(user);

        return Result.success(user);
    }

    @PostMapping("/register")
    public Result register(@RequestBody User user){
        return userService.register(user);
    }

    //返回用户列表
    @PostMapping("/user/list")
    public Result userList(@RequestBody(required = false) User user){
        return Result.success(userService.userList(user));
    }
    //返回试卷列表
    @PostMapping("/test/list")
    public Result testList(@RequestBody(required = false) Test test){
        return Result.success(userService.testList(test));
    }
    //返回指定试卷的题目
    @PostMapping("/question/all")
    public Result questionAll(@RequestBody Test_User_Other testUserOther){
        return Result.success(userService.questionAll(testUserOther));
    }
    //删除指定试卷 需要tid
    @PostMapping("/test/delete")
    public Result testDelete(@RequestBody Test_User testUser){
        return Result.success(userService.testDelete(testUser));
    }
    //返回学生分析的内容
    @PostMapping("/analysis/student")
    public Result analysisStudent(@RequestBody User user){
        return Result.success(userService.analysisStudent(user));
    }
    //删除指定学生分析 需要tid
    @PostMapping("/analysis/student/delete")
    public Result analysisStudentDelete(@RequestBody Analysis_Student analysisStudent){
        return Result.success(userService.analysisStudentDelete(analysisStudent));
    }
    //返回学生分析的内容
    @PostMapping("/analysis/teacher")
    public Result analysisTeacher(@RequestBody Class c){
        return Result.success(userService.analysisTeacher(c));
    }
    //删除指定学生分析 需要tid
    @PostMapping("/analysis/teacher/delete")
    public Result analysisTeacherDelete(@RequestBody Analysis_Teacher analysisTeacher){
        return Result.success(userService.analysisTeacherDelete(analysisTeacher));
    }
    //AI问答
    @PostMapping("/question")
    public Result question(@RequestBody String content){
        String question = "问题:" + content;
        String data = sparkService.questionContent(question);
        return Result.success(data);
    }
    @PostMapping("/resetPassword")
    public Result resetPassword(@RequestBody User user){
        return userService.resetPassword(user);
    }
}
